﻿#ifndef PRINTERMANAGER_H
#define PRINTERMANAGER_H

#include <QPrinter>
#include <QPrinterInfo>
#include <QDebug>
#include <QTextDocument>
#include <QPainter>
#include <QDateTime>
#include <QQuickImageProvider>
#include <QQmlApplicationEngine>
#include <cmath>
#include <xlsxdocument.h>
#include "StaticProperties.h"
#include "reportManager.h"
#include <QAxObject>


// 导出报告
class PrintPreviewProvider: public QObject, public QQuickImageProvider
{
    Q_OBJECT
public:
    PrintPreviewProvider();
    QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
    QImage* pm;
};




class PrinterManager : public QObject
{
    Q_OBJECT

private:
    PrinterManager();



public:
    static PrinterManager& I();

    void initProvider(QQmlApplicationEngine* engine);

    Q_INVOKABLE QStringList getPrinterList();
    Q_INVOKABLE void print(QString printerName);
    Q_INVOKABLE void refreshPreview(double dp);

    // excel版本的，重新获取报告数据，顺便返回能谱图的内容（从本地的导出报告获取），获取完通过楼下的两个函数获取log和info
    Q_INVOKABLE void refreshReportInfo();
    Q_INVOKABLE QVariantMap getExpInfo();
    Q_INVOKABLE QVariantList getLogInfo();


    QPainter* generatePainter();     // 基于QPainter绘制打印内容
    void painterDrawExpInfo(QPainter* painter);
    void painterDrawExpLog(QPainter* painter);


    Q_INVOKABLE int printExcel(QString filePath = "E:\\Code\\Qt\\pkzi__boky__NCDIS2\\build-nuclide-Desktop_Qt_5_14_2_MinGW_64_bit-Debug\\report\\autoExport_实验20251113151731.xlsx");           // 0打印成功 -1连接excel失败


    QString generateHTML();

private:

    int BH = 935;
    int BW = 720;

    QFont font1;
    QFont font2;


    double dp = 1;

    PrintPreviewProvider* provider = nullptr;     // word打印报告的provider(已弃用)
    PrintPreviewProvider* provider_chrom = nullptr;       // 能谱图的provider
    QImage* image = nullptr;
    QImage* image_chrom = nullptr;

    QVariantMap  expInfo;
    QVariantList logInfo;

};

#endif // PRINTERMANAGER_H
